package com.metagurukul.informer.utility;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Validator {
	private Pattern pattern;
	private Matcher matcher;

	private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	private static final String AGE_PATTERN = "^[0-9]+$";
	//private static final String NAME_PATTERN = "^[a-zA-Z]+$";
	private static final String NAME_PATTERN = "^[A-Za-z ]+$";

	public Validator() {
	}

	/**
	 * emailValidate value with email regular expression
	 * 
	 * @param value
	 *            value for validation
	 * @return true valid value, false invalid value
	 */
	public boolean emailValidate(String value) {

		pattern = Pattern.compile(EMAIL_PATTERN);
		matcher = pattern.matcher(value);
		return matcher.matches();

	}

	/**
	 * Validate value with regular expression
	 * 
	 * @param value
	 *            value for validation
	 * @return true valid value, false invalid value
	 */
	public boolean ageValidate(String value) {

		pattern = Pattern.compile(AGE_PATTERN);
		matcher = pattern.matcher(value);
		return matcher.matches();

	}

	public boolean nameValidator(String value) {
		pattern = Pattern.compile(NAME_PATTERN);
		matcher = pattern.matcher(value);
		return matcher.matches();
	}
}
